/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
//作者:AKPower
//算法:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

ll ansx, ansy;

void dfs(ll x, ll y, ll n, ll m, ll flag)
{
    if (m == 1 || n == 1)
    {
        ansx = x;
        ansy = y;
        return;
    }
    ll nl = n / 2;
    ll k = ((m - 1) / (nl * nl));
    if (flag == 1)
    {
        if (k == 0)
        {
            dfs(x, y, n / 2, m, 2);
            return;
        }
        if (k == 1)
        {
            dfs(x, y + n / 2, n / 2, m - (nl * nl), 1);
            return;
        }
        if (k == 2)
        {
            dfs(x + n / 2, y + n / 2, n / 2, m - (2 * nl * nl), 1);
            return;
        }
        if (k == 3)
        {
            dfs(x + n - 1, y + n / 2 - 1, n / 2, m - (3 * nl * nl), 3);
            return;
        }
    }
    if (flag == 2)
    {
        if (k == 0)
        {
            dfs(x, y, n / 2, m, 1);
            return;
        }
        if (k == 3)
        {
            dfs(x + n / 2 - 1, y + n - 1, n / 2, m - (3 * nl * nl), 4);
            return;
        }
        if (k == 2)
        {
            dfs(x + n / 2, y + n / 2, n / 2, m - (2 * nl * nl), 2);
            return;
        }
        if (k == 1)
        {
            dfs(x + n / 2, y, n / 2, m - (nl * nl), 2);
            return;
        }
    }
    if (flag == 3)
    {
        if (k == 0)
        {
            dfs(x, y, n / 2, m, 4);
            return;
        }
        if (k == 1)
        {
            dfs(x - n / 2, y, n / 2, m - (nl * nl), 3);
            return;
        }
        if (k == 2)
        {
            dfs(x - n / 2, y - n / 2, n / 2, m - (2 * nl * nl), 3);
            return;
        }
        if (k == 3)
        {
            dfs(x - n / 2 + 1, y - n + 1, n / 2, m - (3 * nl * nl), 1);
            return;
        }
    }
    if (flag == 4)
    {
        if (k == 0)
        {
            dfs(x, y, n / 2, m, 3);
            return;
        }
        if (k == 1)
        {
            dfs(x, y - n / 2, n / 2, m - (nl * nl), 4);
            return;
        }
        if (k == 2)
        {
            dfs(x - n / 2, y - n / 2, n / 2, m - (2 * nl * nl), 4);
            return;
        }
        if (k == 3)
        {
            dfs(x - n + 1, y - n / 2 + 1, n / 2, m - (3 * nl * nl), 2);
            return;
        }
    }
    return;
}

int main()
{
    IOS;
    ll n, m;
    cin >> n >> m;
    dfs(1, 1, n, m, 1);
    cout << ansx << " " << ansy << endl;
    getchar();
    getchar();
    return 0;
}
